import { POST, GET } from './axios.config.js'
import { downloadInLink, obj2QueryParams } from '@utility/utility'

const base = window.config.ip
const projectName = '/admin'
const projectName1 = '/business'

// 获取用户信息
export const getUserInfoApi = p => GET(`${base}${projectName}/user/info`, p)

// 多文件上传
export const uploadFiles = (fileForm, onProgress) =>
  POST(`${module}/sa-file-baseInfo/uploadFiles`, fileForm, {
    onUploadProgress: event => {
      const progress = (event && Math.floor((event.loaded * 100) / event.total)) || 0
      if (onProgress) {
        onProgress(progress)
      }
    },
    headers: {
      hideLoading: true,
    },
  })
export const downloadFile = id => {
  const url = `${module}/file/downLoad?id=${id}`
  downloadInLink(url)
}

// 导出
export const exportComplaintList = ({
  userId,
  searchContent,
  startTime,
  endTime,
  statusList,
  messageTypeList,
  organIdList,
  remarkParamList,
}) => {
  const queryParams = obj2QueryParams({
    userId,
    searchContent,
    startTime,
    endTime,
    statusList,
    messageTypeList,
    organIdList,
    remarkParamList,
  })
  const href = `${base}/skipValidation/downloadAll?${queryParams}` // 导出文件
  downloadInLink(href)
}

// 获取单级字典列表
export const getListDictApi = p => POST(`${base}${projectName1}/wsDict/listDict`, p)

// 获取多级字典列表
export const getListDictTreeApi = p => POST(`${base}${projectName1}/wsDict/listDictTree`, p)
